<?php
namespace App\Library\System\Model;

use App\Library\System\Model;

/**
 * Skill Model
 *
 * @category   Model
 * @package    App\Library\System\Model
 * @author     Nam Vo <vhnam@peslook.com>
 * @copyright  Peslook
 * @version    1.0
 * @since      Class available since Release 1.0
 */
class LanguageModel extends Model
{
    /**
     * Constructor
     *
     * @param string|int $id
     */
    public function __construct($id = null)
    {
        parent::__construct();

        if (is_null($id))
        {
            return;
        }

        $field = is_numeric($id) ? 'id' : 'alias';

        $language = $this->one($this->select()
                                    ->from('language')
                                    ->where(array(
                                        $field => $id
                                    ))
        );

        if ($language) {
            $this->add($language);
        }
    }

    public function isValid()
    {
        return isset($this->id) ? true : false;
    }

    public function getAllLanguages()
    {
        return $this->more($this->select()
                    ->from('language')
        );
    }
}